import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path';
// element-plus自动导入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
  plugins: [
    vue(),

    // element-plus自动导入
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],

  // src文件夹配置别名
  resolve: {
    alias: {
      "@": path.resolve(__dirname, 'src')
    }
  },

  //代理服务器解决跨域 
  server: {
    proxy: {
      '/api': {
        target: 'http://47.108.153.130:8090',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
        onProxyReq: (proxyReq, req, res) => {
          console.log('代理请求:', req.url, '->', proxyReq.path);
        }
      }
    }
  }
})
